package com.wiselink.fastbox.orderplacement;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.wiselink.exception.FastBoxException;
import com.wiselink.fastbox.FastBoxBaseAPI;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单信息查询
 */
public class OrderInformationQuery extends FastBoxBaseAPI {

    private final String fbInvoiceNo;
    private ResultVO vo = new ResultVO();

    public OrderInformationQuery(String fbInvoiceNo) {
        this.fbInvoiceNo = fbInvoiceNo;
    }

    @Override
    public String getPath() {
        return "/api/order/detail";
    }

    @Override
    public Map<String, String> getRequestParam() {
        return new HashMap<String, String>() {{
            put("fb_invoice_no", fbInvoiceNo);
        }};
    }

    @Override
    public String getRequestData() {
        return "";
    }

    @Override
    public void processResponseResult(JSONObject jsonResult) {
        log.debug(">>>处理 查询订单信息 响应结果<<<");
        JSONObject meta = jsonResult.getJSONObject("meta");
        Integer code = meta.getInteger("code");
        String message = meta.getString("message");
        switch (code) {
            case 200:
                JSONArray response = jsonResult.getJSONArray("response");
                log.debug("查询订单成功 response: {}", response);
                break;
            case 440:
            case 441:
                throw new FastBoxException("必需参数错误：缺失或无效值. message:" + message);
            case 500:
                throw new FastBoxException("内部处理错误，message:" + message);
            case 600:
                throw new FastBoxException("未知错误（未定义错误）. message:" + message);
            default:
                throw new FastBoxException("查询订单失败 code: " + code);
        }
    }

    public ResultVO getResult() {
        return vo;
    }

    public static class ResultVO {
    }
}
